import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/config/home_images.dart';
import 'package:juming_test/model/home/home_kingkong_model.dart';
import 'package:juming_test/routes/app_router.gr.dart';
import 'package:auto_route/auto_route.dart';

class HomeKingkong extends StatelessWidget {
  const HomeKingkong({super.key, required this.kingkongList});
  // 金刚位数据
  final List<HomeKingkongModel> kingkongList;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.all(16.w),
      width: double.infinity,
      child: Wrap(
        spacing: 12.w,
        runSpacing: 12.w,
        children: [
          ...kingkongList.take(11).map((item) => _buildKingkongItem(item)),
          _buildMoreButton(context),
        ],
      ),
    );
  }

  // 构建金刚位Item
  Widget _buildKingkongItem(HomeKingkongModel item) {
    return InkWell(
      onTap: () {},
      child: SizedBox(
        width: 80.w,
        height: 80.w,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(item.iconPath, width: 40.w, height: 40.w),
            SizedBox(height: 6.w),
            Text(
              item.title,
              style: TextStyle(fontSize: 14.sp),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }

  // 构建“更多”按钮
  Widget _buildMoreButton(BuildContext context) {
    return InkWell(
      onTap: () {
        context.pushRoute(HomeKingkongManagementRoute());
      },
      child: SizedBox(
        width: 80.w,
        height: 80.w,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(
              HomeImages.homeKingkongMorePng,
              width: 40.w,
              height: 40.w,
            ),
            SizedBox(height: 6.w),
            Text(
              '更多/管理',
              style: TextStyle(fontSize: 14.sp),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }
}
